package com.jameskarl.amap.map.apis

import android.content.Context
import com.amap.api.location.AMapLocation
import com.amap.api.location.AMapLocationClient
import com.amap.api.location.AMapLocationClientOption


object LocationService {

    private lateinit var locationClient: AMapLocationClient

    fun init(context: Context) {
        locationClient = AMapLocationClient(context)
        // 初始化定位参数
        val locationOption = AMapLocationClientOption()
        // 设置定位模式为高精度模式，Battery_Saving为低功耗模式，Device_Sensors是仅设备模式
        //locationOption.locationMode = AMapLocationClientOption.AMapLocationMode.Hight_Accuracy
        // 设置定位间隔,单位毫秒,默认为2000ms
        //locationOption.interval = 2000
        locationOption.locationPurpose = AMapLocationClientOption.AMapLocationPurpose.SignIn
        locationOption.isOnceLocation = true
        locationClient.setLocationOption(locationOption)
    }

    fun getCurrentLocation(callback: (location: AMapLocation) -> Unit) {
        locationClient.setLocationListener { callback(it) }
        locationClient.startLocation()
    }
}